#define _CRT_SECURE_NO_WARNINGS 1
#include "Stack.h"
Stack::Stack(int capacity)
	:_capacity(capacity)
	, _arr(nullptr)
	, _size(0)
{
	STDateType* newArr = (STDateType*)malloc(sizeof(STDateType) * _capacity);
	if (newArr == nullptr)
	{
		perror("Stack::malloc error!\n");
		return;
	}
	_arr = newArr;
	newArr = NULL;
}
Stack::~Stack()
{
	free(_arr);
	_arr = nullptr;
	_capacity = _size = 0;
}
Stack::Stack(const Stack& s)
{
	STDateType* newArr = (STDateType*)malloc(sizeof(STDateType) * s._capacity);
	if (newArr == nullptr)
	{
		perror("Stack::malloc error!\n");
		return;
	}
	_arr = newArr;
	newArr = nullptr;
	_capacity = s._capacity;
	_size = s._size;
	for (int i = 0; i < s._size; i++)
	{
		*(_arr + i) = *(s._arr + i);
	}
}
void Stack::PushSt(STDateType index)
{
	if (_size == _capacity)
	{
		_capacity *= 2;
		STDateType* newArr = (STDateType*)realloc(_arr,sizeof(STDateType) * _capacity);
		if (newArr == nullptr)
		{
			perror("PushSt::realloc error!");
			return;
		}
		_arr = newArr;
	}
	*(_arr + _size++) = index;
}
void Stack::PopSt()
{
	assert(_size);
	--_size;
}
int Stack::TopSt()
{
	assert(_size);
	return *(_arr + _size - 1);
}
bool Stack::EmptySt()
{
	return !_size;
}
int Stack::SizeSt()
{
	return _size;
}
//void Stack::operator=(const Stack& st)
//{
//	STDateType* newArr = (STDateType*)malloc(sizeof(STDateType) * st._capacity);
//	if (newArr == nullptr)
//	{
//		perror("operator=::malloc error!\n");
//		return;
//	}
//	_arr = newArr;
//	newArr = nullptr;
//	_capacity = st._capacity;
//	_size = st._size;
//	for (int i = 0; i < st._size; i++)
//	{
//		*(_arr + i) = *(st._arr + i);
//	}
//}